<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="uct" uri="/WEB-INF/uct.tld" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <%@ include file="/common/sale/include/common-base.jsp"%>	
  <script type="text/javascript" src="/js/jquery-md5-min.js"></script>
  <script src="${ctx}/js/tools-login.js"></script>
  <title>交易商开户-${titleName}</title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<script>
  var add_url = "${ctx}/res/uct/admin/saveUser";
  var del_url = "${ctx}/res/uct/admin/delUser";
  var view_url = "${ctx}/trans/info/userInfo";
  //var org_url = "${ctx}/uct/org/org!initOrg.action";
  var org_url = "${ctx}/trans/list/orgInit";
  var dept_url = "${ctx}/trans/list/deptInit";//?orgId=${item.orgId}
  var id;
</script>
</head>
<body class="hold-transition ${sysColor} sidebar-mini">
	<div class="wrapper">
		<!-- top start -->
		<%@include file="/common/sale/top.jsp" %>
		<!-- top end -->
		<!-- left start -->
		<%@include file="/common/sale/left.jsp" %>
		<!-- left end-->
		<!-- right start -->
		<div class="content-wrapper">
			<div class="content">
				<div class="box box-success">
	            	<div class="box-header with-border">
	            		<h3 class="box-title"><i class="fa fa-user"></i> 交易商开户</h3>
	            	</div>
	            	<div class="box-body col-sm-offset-2" id="userFormData" style="text-align: center;">
						<form class="form-horizontal" role="form" id="userForm" name="frm1">
							<input type="hidden" name="formToken" id="formToken">
							<input type="hidden" name="userId" id="userId" data-name="userId">
							<input type="hidden" name="userPass" id="md5Pass" value=""/>	
							<input type="hidden" name="randCodeMark" value="F">
							<input type="hidden" name="deptId" id="userForm_deptId">
							<input type="hidden" name="orgId" id="userForm_orgId">
							<input type="hidden" name="userType" value="member">
							<input type="hidden" name="delStatus" value="0">
							<input type="hidden" name="userStatus" value="0" >
							<div class="form-group">
								<label for="inputOrgCname" class="col-sm-2 control-label" ><font color="red" style="vertical-align: middle;">*</font>账号</label>
								<div class="col-sm-6">
									<input type="text" class="form-control clean" data-name="userEname" name="userEname"
									 placeholder="必填项"/>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-2 control-label"><font color="red" style="vertical-align: middle;">*</font>姓名</label>
								<div class="col-sm-6">
									<input type="text" class="form-control clean"  name="userCname" data-name="userCname"  placeholder="必填项">
								</div>
							</div>
							<div id="if_update_pass_div" class="form-group" style="display: none">
								<label class="col-sm-2 control-label">是否修改密码</label>
								<div class="col-sm-6">
									<input type="radio" name="if_update_pass" id="if_update_pass" value="1" onclick="setUserPass('1')"/>是
									<input type="radio" name="if_update_pass" id="if_update_pass" value="0" checked="checked" onclick="setUserPass('0')"/>否
								</div>
							</div>
							<div id="edit_user_pass">
								<div class="form-group">
								<label class="col-sm-2 control-label"><font color="red" style="vertical-align: middle;">*</font>密码</label>
								<div class="col-sm-6">
									<input type="password" name="pw" class="form-control clean" id="password">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-2 control-label"><font color="red" style="vertical-align: middle;">*</font>确认密码</label>
								<div class="col-sm-6">
									<input type="password" class="form-control clean" name="pw" id="password2"  type="password">
								</div>
							 </div>
							 </div>
							 <div class="form-group">
								<label class="col-sm-2 control-label">邮箱</label>
								<div class="col-sm-6">
									<input type="text" class="form-control clean" name="email" data-name="email" placeholder="">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-2 control-label">用户性别</label>
								<div class="col-sm-6" id="userSexDiv" style="text-align: left;"></div>
							</div>
							<div class="form-group">
								<label class="col-sm-2 control-label"><font color="red" style="vertical-align: middle;">*</font>手机号</label>
								<div class="col-sm-6">
									<!-- <input id="phone" type="text" class="form-control clean" maxlength="11" name="mobile" data-name=mobile placeholder="必填项"> -->
									<input type="text" onblur="checkUserMobile('frm1',1)" value="" class="form-control clean" name="mobile" id="frm1_login_mobile" tip="请输入手机号码" placeholder="请输入手机号码" abc="1" style="color: rgb(0, 0, 0);">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-2 control-label">联系电话</label>
								<div class="col-sm-6">
									<input type="text" class="form-control clean" name="phone" data-name="phone" placeholder="非必填项">
								</div>
							</div>
							<div class="box-footer col-sm-8">
								<button type="button" class="btn btn-primary col-sm-2 col-sm-offset-4" onclick="cleanData('userForm');">重置</button>
								<button type="button" class="btn btn-primary col-sm-2 col-sm-offset-2" onclick="add('userForm');">提 交</button>
							</div>
						</form>
	            	</div>
            	</div>
			</div>
		</div>
		<!-- right end -->
	</div>
	<!-- bottom start-->    
	<%@include file="/common/sale/foot.jsp" %>
	<!-- bottom end -->
</body>
<script>
var clickMenu= 'transuser-add';
//初始化
$(function(){
	console.log('${loginUser.deptId}')
	$("#userForm_orgId").val('${loginUser.orgId}');
	$("#userForm_deptId").val('${loginUser.orgId}');
	DictUtil.getDictExtList("#userType", dictUrl, {cateEname:"userType"});//用户类型
	DictUtil.getRadioList("#userSexDiv","userSex", dictUrl,{cateEname:"userSex"});//用户性别
	//初始化验证
	setValidate("userForm");
});
function add(formId){
		var pass = $("#password").val();
	    var pass2 = $("#password2").val();
	    if($.trim(pass) != $.trim(pass2)){
	    	$.messager.alert('错误提示', '两次输入密码不一致!', 'error');
	    	return;
	    }else{
	    	$("#md5Pass").val(pass.md5());
	    }
	    $('#'+formId).data('bootstrapValidator').validate();  
		if(!$('#'+formId).data('bootstrapValidator').isValid()){  
	    	return ;  
		} 
		if(checkUserMobile("frm1",1)==false){
			return;
		}
		_submit(formId);
}

function _submit(formId){
   $.ajax({type:'post', url:add_url,dataType:'json',
	    data:$("#"+formId).serialize(),
	    success: function(myData){
	    	//console.log(myData);
	    	/* layer.alert(myData.msg, {
                skin: 'layui-layer-lan'
                ,closeBtn: 0 
            });*/
	    	 layer.alert("保存成功，可进行账户审核");
             cleanData(formId);
             cleanJiaoyan(formId);
	       	 refresh();
	  	}
	});	
}

//清空校验规则
function cleanJiaoyan(formId){
		var validate = $('#'+formId).data('bootstrapValidator').validate();
		validate.resetForm();
}


function setUserPass(ifPass){
    if("1"==ifPass){
        $("#edit_user_pass").show();
    }else{
        $("#edit_user_pass").hide();
    }
}


function cleanData(id){
	$('#'+id).find(".clean").val("");//按照样式清空；
	cleanJiaoyan("userForm");
}

function setValidate(formId){
	
	$('#'+formId).bootstrapValidator({
	 //   excluded: [':disabled'],
	    feedbackIcons: {
	     //   valid: 'glyphicon glyphicon-ok',
	        invalid: 'glyphicon glyphicon-remove',
	        validating: 'glyphicon glyphicon-refresh'
	    },
	    fields:{
	    	userEname: {/*键名和input name值对应*/
              message: 'The username is not valid',
              validators: {
                  notEmpty: {/*非空提示*/
                      message: '账号不能为空'
                  },
                  stringLength: {/*长度提示*/
                      min: 6,
                      max: 26,
                      message: '用户名长度必须在6到26之间'
                  }/*最后一个没有逗号*/
              }
          },
			userCname:{
					message: 'The username is not valid',
					validators:{
						notEmpty:{
							message:'姓名不能为空'
						},
						regexp:{
							regexp:'[\u4e00-\u9fff]',
							message:'请输入中文'
						}
				}
			},
			pw: {
                 message:'密码无效',
                 validators: {
                     notEmpty: {
                         message: '密码不能为空'
                     },
                     stringLength: {
                         min: 6,
                         max: 24,
                         message: '密码长度必须在6到24之间'
                     },
                     identical: {//相同
                         field: 'pw', //需要进行比较的input name值
                         message: '两次密码不一致'
                     },
                     regexp: {
                         regexp: /^[A-Za-z].*[0-9]|[0-9].*[A-Za-z]$/,
                         message: '密码必须由数字和英文字母组成！'
                     }
                 }
             },
			/**
			,email:{
             	validators:{
             		emailAddress:{
             			message:'请输入正确的邮箱地址'
             		}
             	}
             }*/
			mobile: {
				message:'手机号不正确',
                validators: {
                    notEmpty: {
                        message: '手机号不能为空'
                    }
                   /* regexp: {
                        regexp: /^1[34578]\d{9}$/,
                        message: '手机号格式不正确！'
                    }*/
                }
			}
	    }
	});
}

/**
 * 用户手机号校验
 * type 1 注册 2 找回密码 3 重新绑定手机号
 */
function checkUserMobile(formId,type){
	var mobile ="#"+formId+"_login_mobile";
	if(type=="3"){
		//判断是否和原手机号一样
		var oldMobile = $("#oldMobile").val();
		if(oldMobile==$(mobile).val()){
			layer.msg("新手机号不能与原手机号相同", {offset: '200px'});
			$(mobile).focus();
			return false;
		}
	}
	if(strIsNull($(mobile).val())){
		layer.tips($(mobile).attr("tip"), mobile, {tips: 1});
		$(mobile).focus();
		return false;
	}
	//验证手机号长度
	if(!checkMobileLen($(mobile).val())){
		layer.msg("手机号位数不足11位", {offset: '200px'});
		$(mobile).focus();
		return false;
	}
	//验证手机号
	if (!checkmobile($(mobile).val())){
		layer.msg("请输入正确的手机号", {offset: '200px'});
		$(mobile).focus();
		return false;
	}
	var formUrl = ctx+"/trans/list/?doCode=dymicSql";
	//var dataP = {'member.w_mobile':$(mobile).val(),'modelTypes':'s_member'};
	var dataP = {'uctUser.w_mobile':$(mobile).val(),'modelTypes':'s_uctUser'};
	var result;
	$.ajax({url: formUrl,type: 'get',data:dataP,cache: false,async:false,dataType:'json',
		success: function(data){result=data;},error:function(messg)  { alert("错误信息:连接服务器失败");}  
	});
	if(result.total>0){
		if(type=="1"){
			layer.msg("该手机号已被绑定", {offset: '200px'});
			$(mobile).val("");
			return false;
		}else if(type=="2"){//找回密码填充userEname
			//$("#username").val(result.rows[0].memberEname);
		}else if(type=="3"){
			layer.msg("该手机号已被绑定", {offset: '200px'});
			return false;
		}
	}else{
		if(type=="2"){
			layer.msg("系统不存在该手机号", {offset: '200px'});
			$(mobile).val("");
			$(mobile).focus();
			return false;
		}
	}
	return true;
}

</script>
</html>
